﻿
using System.AuthCenter.DBModels;

using GCC.Container.Abstracts;

namespace System.AuthCenter
{
    public class GCCEntrance : AbsEntrance
    {

        public override bool IsRelease()
        {
#if DEBUG
            return false;
#else
            return true;
#endif
        }

        public override string Name()
        {
            return "System.AuthCenter";
        }

        public override Version NeedsApiContainerVersion()
        {
            return new Version(0, 0, 0, 0);
        }

        public override void OnGetDBInstance()
        {
            if (GCCEntrance.DBManager is null || GCCEntrance.DBManager.GlobalReadDB is null)
            {
                GCCLoggerProvider!.CreateLogger<GCCEntrance>().Critical("The Global read db instance was null, init auth center faild.");
                return;
            }
            var roles = GCCEntrance.DBManager.GlobalReadDB.Select<Roles>().ToList();
            roles.ForEach(item =>
            {
                AuthManager._roles.Add(item);
            });
            var scopes = GCCEntrance.DBManager.GlobalReadDB.Select<Scopes>().ToList();
            scopes.ForEach(item =>
            {
                AuthManager._scopes.Add(item);
            });
        }

        public override void OnSystemStarted(AbsGCCContext context)
        {
#if DEBUG
            AuthManager.LoginTestUser(context, out var _);
#endif
        }

        public override void SystemTryShutDown()
        {
        }
    }
}
